<?php

class sort extends Front {

    public function index( $c ) {

        $limit = empty( $this->setting[ 'article_num' ] ) ? 10 : $this->setting[ 'article_num' ];

        if ( $id = intval( R( 'id' ) ) ) {
            $sid = $this->Node()->treeID( $this->sort, $id );
        } elseif ( $alias = R( 'alias' ) ) {
            $alias = trim( $alias, '/' );
            $sid = $this->Node()->treeAlias( $this->sort, $alias );
            $id = current( $sid );
        }

        $sid = implode( ',', $sid );

        $this->model->table = 'article';
        $result = $this->Pager( $limit )->findAll( "sid in ({$sid})", 'isTop desc, id desc' );

        $titles = $title = $this->sort[ $id ][ 'title' ];
        $keywords = $this->sort[ $id ][ 'keyword' ] ? $this->sort[ $id ][ 'keyword' ] : $this->setting[ 'webkey' ];
        $description = $this->sort[ $id ][ 'description' ] ? $this->sort[ $id ][ 'description' ] : $this->setting[ 'webdesc' ];
        include $this->display( 'index' );
    }
}